<?php

class emails extends CI_Controller {

    function __construct() {
        parent::__construct();
        if ($this->session->userdata('logged_in')) {
            $session_data = $this->session->userdata('logged_in');
            $data['username'] = $session_data['username'];
        } else {
            redirect('user_login/user', 'refresh');
        }
        $this->load->model('user');
        $this->load->model('user_role');
        $this->load->model('email');
        $this->load->library('user_id');
        $this->load->helper('user_helper');
        if ($this->cek() == 0) {
            redirect('user_login/user', 'refresh');
        }
    }

    function index() {
        $data['id'] = $this->user_id->id();
        
        $rows = $this->email->index();
        $data['i'] = 1;
        $data['access'] = $this->user_role->access($this->cek());
        $data['rows'] = $this->email->index();
        $data['content'] = 'emails/index';
        $this->load->view('template/user', $data);
    }

    function show() {
        $data['id'] = $this->user_id->id();
        
        $id = $this->uri->segment(3);
        $data['access'] = $this->user_role->access($this->cek());
        $data['rows'] = $this->email->show($id);
        $data['content'] = 'emails/show';
        $this->load->view('template/user', $data);
    }

    function baru() {
        $data['id'] = $this->user_id->id();
        
        $data['access'] = $this->user_role->access($this->cek());
        $data['content'] = 'emails/new';
        $this->load->view('template/user', $data);
    }

    function create() {
        $email = $this->input->post('email', TRUE);
        $this->email->create($email);
    }

    function edit() {
        $data['id'] = $this->user_id->id();
        
        $id = $this->uri->segment(3);
        $data['access'] = $this->user_role->access($this->cek());
        $data['rows'] = $this->email->edit($id);
        $data['content'] = 'emails/edit';
        $this->load->view('template/user', $data);
    }

    function update() {
        $id = $this->input->post('id', TRUE);
        $email = $this->input->post('email', TRUE);
        $this->email->update($id, $email);
    }

    function id() {
        $session_data = $this->session->userdata('logged_in');
        return $session_data['id'];
    }

    function cek() {
        $level = $this->user->cek($this->id());
        if ($level) {
            $level;
        } else {
            $level = 0;
        }
        return $level;
    }

    function send() {
//        $this->load->library('email');
//
//        $this->email->from('chaerul.developer@gmail.com', 'chaerul');
//        $this->email->to('chaerul.developer@gmail.com');
//        $this->email->cc('');
//
//        $this->email->subject('Email Test');
//        $this->email->message('Testing the email class.');
//
//        $this->email->send();
        
        
//        $this->load->library('email');
//
//        $this->email->from('chaerul.developer@gmail.com', 'chaerul');
//        $this->email->to('chaerul_u@rocketmail.com');
//        $this->email->cc('');
//
//        $this->email->subject('Email Test');
//        $this->email->message('<a href="http://stasiuntiket.baradeveloper.com/$username">Testing the email class.</a>');
        echo("Thanks for confirmation in stasiuntiket.com for compleate regisration please confirmation http://stasiuntiket.baradeveloper.com/comfirm/$username");

//        $this->email->send();
        

        //echo $this->email->print_debugger();
    }

}

?>
